home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig06_12.jar / Ch06 / Fig06_12 / Fig06_12.cpp
C/C++ Source or Header  |  1997-10-16  |  945b  |  47 lines

  1. // Fig. 6.12: fig06_12.cpp 
  2. // Demonstrating that class objects can be assigned
  3. // to each other using default memberwise copy
  4. #include <iostream.h>
  5.  
  6. // Simple Date class
  7. class Date {
  8. public:
  9.    Date( int = 1, int = 1, int = 1990 ); // default constructor
  10.    void print();
  11. private:
  12.    int month;
  13.    int day;
  14.    int year;
  15. };
  16.  
  17. // Simple Date constructor with no range checking
  18. Date::Date( int m, int d, int y )
  19. {
  20.    month = m;
  21.    day = d;
  22.    year = y;
  23. }
  24.  
  25. // Print the Date in the form mm-dd-yyyy
  26. void Date::print() 
  27.    { cout << month << '-' << day << '-' << year; }
  28.  
  29. int main()
  30. {
  31.    Date date1( 7, 4, 1993 ), date2;  // d2 defaults to 1/1/90
  32.  
  33.    cout << "date1 = ";
  34.    date1.print();
  35.    cout << "\ndate2 = ";
  36.    date2.print();
  37.  
  38.    date2 = date1;   // assignment by default memberwise copy
  39.    cout << "\n\nAfter default memberwise copy, date2 = ";
  40.    date2.print();
  41.    cout << endl;
  42.  
  43.    return 0;
  44. }
  45.  
  46.  
  47.